package com.ham.mud.state.edit;

import com.ham.mud.ServerConnection;
import com.ham.mud.TargetableService;
import com.ham.mud.commands.LookCommand;
import com.ham.mud.state.ConnectionState;
import com.ham.mud.state.PlayingState;

import java.util.Arrays;

/**
 * Created by hlucas on Jul 18, 2011 at 10:09:00 AM
 */
public class EditState extends ConnectionState {
    
    public EditState(ServerConnection connection) {
        super(connection);
        editWhat();
    }

    @Override
    public void processInput(String line) {
        if(line.equals("exit")) {
            exit();
            return;
        }

        String target = TargetableService.findTarget(line, Arrays.asList("room", "item", "mob"));
        if(target == null) {
            connection.println("That is not an option.");
            editWhat();
            return;
        }

        if(target.equals("room")) {
            connection.changeState(new EditRoomState(connection));
        } else if(target.equals("item")) {
            connection.changeState(new EditItemState(connection));
        } else if(target.equals("mob")) {
            connection.changeState(new EditMobState(connection));
        }
    }

    private void exit() {
        connection.printStart("-----------------------------");
        connection.println("----- EXITING EDIT MODE -----");
        connection.println("-----------------------------");
        connection.println();
        connection.changeState(new PlayingState(connection));
        new LookCommand().execute(connection);
    }

    private void editWhat() {
        connection.print("Edit what? (room, item, mob): ");
    }

    @Override
    public void tick() {

    }
}
